package my.mybatis.common.util;

import org.apache.ibatis.jdbc.SQL;

/**
 * @Author:wangbin.
 * @Description.
 * @Date:Created in 15:10 2017/9/20.
 * @Modified By:
 */
public class SQLBuild {

    /**
     * 使用sql构造器，此SQL构造器可以帮你自动组装语句，不用再关心关键字的位置或者顺序
     * 可以当小工具来构造自己的sql
     * @return
     */
    public static String selectPersonSql() {
        // example
        return new SQL() {{
            SELECT("P.ID, P.USERNAME, P.PASSWORD, P.FULL_NAME");
            FROM("PERSON P");
            INNER_JOIN("DEPARTMENT D on D.ID = P.DEPARTMENT_ID");
            WHERE("P.ID = A.ID");
            WHERE("P.FIRST_NAME like ?");
            OR();
            WHERE("P.LAST_NAME like ?");
            GROUP_BY("P.ID");
            HAVING("P.LAST_NAME like ?");
            OR();
            HAVING("P.FIRST_NAME like ?");
            INNER_JOIN("COMPANY C on D.COMPANY_ID = C.ID");
            ORDER_BY("P.ID");
            FROM("ACCOUNT A");
            ORDER_BY("P.FULL_NAME");
            SELECT("P.LAST_NAME, P.CREATED_ON, P.UPDATED_ON");
        }}.toString();
    }
}
